package YAPserver.behaviours;

import YAPserver.collisionEngine.*;
import YAPserver.gameObjects.Point;
/**
 * This class implements BounceBehaviour. Apart from special bounce behaviours caused by mods
 * all types of bounce should extend this class. The only method that should be implemented
 * is calcNewAngle.
 * @author Daniel
 *
 */
public abstract class BounceAbstract implements BounceBehaviour {
	@Override
	public void bounce(Ball ball, Wall wall) {
//		Point q = Tool.intersection(ball, wall);
		Point q = Collision.intersection(ball, wall);
		double newAngle = calcNewAngle(ball, wall);
		ball.setAngle(newAngle);
		Point radiusVec = new Point(wall.getNormal());
		radiusVec.scalarMult(ball.getRadius());
		ball.setNextMiddlePoint(q.add(radiusVec));
	}
	/**
	 * Calculates a new angle which is then returned. Typically this method is called
	 * after a collision with another object.
	 * @param ball ballAbstract whose angle is to be changed
	 * @param wall GameObject that has been hit
	 * @return a new angle for the ball
	 */
	abstract protected double calcNewAngle(Ball ball, Wall wall);
}
